import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import {initMenu} from "@/util/menu";

import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import 'font-awesome/css/font-awesome.min.css'

Vue.use(ElementUI);

import {postKeyValueRequest} from "@/util/api";
import {postRequest} from "@/util/api";
import {getRequest} from "@/util/api";
import {putRequest} from "@/util/api";
import {deleteRequest} from "@/util/api";

Vue.prototype.postKeyValueRequest = postKeyValueRequest;
Vue.prototype.postRequest = postRequest;
Vue.prototype.getRequest = getRequest;
Vue.prototype.putRequest = putRequest;
Vue.prototype.deleteRequest = deleteRequest;

Vue.config.productionTip = false

//注册全局导航守卫
router.beforeEach((to, from, next) => {
    if (to.path == '/') {
        //去登录页面
        next();
    } else {

        if (!window.sessionStorage.getItem("currentHr")) {
            // next('/')   // 如果没有登录,就跳到登录页

            //通过访问内页登录,跳转到登录页,之后返回内页,
            // 这里不是跳转的功能逻辑,只是做好标记.在loginview里提取出来再条转
            next('/?redirect=' + to.path)

            return // 跳转了之后,后面就不执行了,
        }
        //这是执行menu.js里面的初始化方法.
        initMenu(router, store);
        //加next 让程序继续执行
        next();
    }
})

new Vue({
    router,
    store,
    render: h => h(App)
}).$mount('#app')
